//
//  QZMessegeVC.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/6/18.
//

#import "QZMessegeVC.h"
#import "DJMessageCell.h"
#import "QZCommentShowCell.h"
#import "DJMessageModel.h"
#import "DJMessageSystemVC.h"
#import "DJMessageFansVC.h"
#import "DJMessageComtentVC.h"
#import "SYCollectionViewRoundFlowLayout.h"
#import "DJMessageLikeVC.h"
#import "DJMessageCollectVC.h"

@interface QZMessegeVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (strong, nonatomic) UICollectionView * messegeTableView;
@property (strong, nonatomic) NSDictionary * messegeDictionary;
@end

@implementation QZMessegeVC
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationItem.title = @"我的消息";
    [self requestMessegeList];
    [self.mm_drawerController setEnableGesture:NO];
}
-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}

- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
}
- (void)configUI{

}
#pragma mark 初始化
- (UICollectionView *)messegeTableView{
    if(_messegeTableView == nil){
//        _messegeTableView = [[UITableView alloc]init];
//        _messegeTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//        _messegeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//        [_messegeTableView registerNib:[UINib nibWithNibName:@"DJMessageCell" bundle:nil] forCellReuseIdentifier:@"DJMessageCell"];
//        _messegeTableView.delegate = self;
//        _messegeTableView.dataSource = self;
//    [self.view addSubview:_messegeTableView];
        
        SYCollectionViewRoundFlowLayout *layout = [[SYCollectionViewRoundFlowLayout alloc]init];
        layout.sectionHeadersPinToVisibleBounds = YES;
        layout.collectionCellAlignmentType = SYCollectionViewFlowLayoutAlignmentTypeByLeft;
        _messegeTableView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, KScreen_H-KNav_H) collectionViewLayout:layout];
        [_messegeTableView registerNib:[UINib nibWithNibName:@"DJMessageCell" bundle:nil] forCellWithReuseIdentifier:@"DJMessageCell"];
        _messegeTableView.backgroundColor = viewback_black;
//        //创建瀑布流布局
//        XRWaterfallLayout *waterfall = [XRWaterfallLayout waterFallLayoutWithColumnCount:3];
//        //或者一次性设置
//        [waterfall setColumnSpacing:2 rowSpacing:2 sectionInset:UIEdgeInsetsMake(5, 0, KSafeAreaBottomHeight+5, 0)];
        //设置代理，实现代理方法
//        waterfall.delegate = self;
//        _historyCollection.collectionViewLayout = waterfall;
        
        _messegeTableView.alwaysBounceVertical = YES;
        _messegeTableView.delegate = self;
        _messegeTableView.dataSource = self;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:_messegeTableView];
    }
    return _messegeTableView;
}
#pragma mark 请求
- (void)requestMessegeList{
    KMutableDic(sendDic)
    KWeakSelf
    [YBNetBase messegeNewsTotalRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [SVProgressHUDTool dismiss];
            weakSelf.messegeDictionary = data[@"list"];
            [weakSelf.messegeTableView reloadData];
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
#pragma mark uitableview delege
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    if(self.messegeDictionary == nil){
        return 0;
    }
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 7;
//    return 8;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DJMessageCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DJMessageCell" forIndexPath:indexPath];
    cell.m_type = indexPath.row;
    if(indexPath.row == 0){
        [cell showMessageCell:self.messegeDictionary[@"fans"]];
    }else if (indexPath.row == 1){
        [cell showMessageCell:self.messegeDictionary[@"comment"]];
    }else if (indexPath.row == 2){
        [cell showMessageCell:self.messegeDictionary[@"like"]];
    }else if (indexPath.row == 3){
        [cell showMessageCell:self.messegeDictionary[@"collect"]];
    }
//    else if (indexPath.row == 4){
//        [cell showMessageCell:self.messegeDictionary[@"interaction"]];
//    }
    else if (indexPath.row == 4){
        [cell showMessageCell:self.messegeDictionary[@"wallet"]];
    }else if (indexPath.row == 5){
        [cell showMessageCell:self.messegeDictionary[@"team"]];
    }else if (indexPath.row == 6){
        [cell showMessageCell:self.messegeDictionary[@"system"]];
    }
    
    return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 6.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 6.0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
 layout:(UICollectionViewLayout *)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(7, 0, 7, 0);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(KScreen_W, 66);
}
- (void)showTextViewSubViewToViewTo1:(UIView * )subView{

    UIView * showTextViewSubViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewSubViewTo1.clipsToBounds = YES;
    [subView addSubview:showTextViewSubViewTo1];
    UILabel * showTextViewSubViewLabelTo2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    showTextViewSubViewLabelTo2.text = @"56464645";
    [showTextViewSubViewTo1 addSubview:showTextViewSubViewLabelTo2];
    
    UIImageView * showTextViewSubViewTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [subView addSubview:showTextViewSubViewTo2];

}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        DJMessageFansVC * vc = [[DJMessageFansVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1){
        DJMessageComtentVC * vc = [[DJMessageComtentVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2){
        DJMessageLikeVC * vc = [[DJMessageLikeVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 3){
        DJMessageCollectVC * vc = [[DJMessageCollectVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
//    else if (indexPath.row == 4){
//        DJMessageSystemVC * vc = [[DJMessageSystemVC alloc]init];
//        vc.m_type = indexPath.row;
//        [self.navigationController pushViewController:vc animated:YES];
//    }
    else if (indexPath.row == 4){
        DJMessageSystemVC * vc = [[DJMessageSystemVC alloc]init];
        vc.m_type = indexPath.row;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 5){
        DJMessageSystemVC * vc = [[DJMessageSystemVC alloc]init];
        vc.m_type = indexPath.row;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 6){
        DJMessageSystemVC * vc = [[DJMessageSystemVC alloc]init];
        vc.m_type = indexPath.row;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

@end
